/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TesteNovoNewRoomBox.java
 *
 * Created on 23/11/2011, 22:37:41
 */
package testenovo;
import cliente.*;
import javax.swing.*;

/**
 *
 * @author yano
 */
import org.jdesktop.application.Action;
public class TesteNovoNewRoomBox extends javax.swing.JFrame {
    private Cliente cliente;
    
    private TesteNovoView framePai;
    private int frameCode;
    /** Creates new form TesteNovoNewRoomBox */
    public TesteNovoNewRoomBox(TesteNovoView pai, int code, Cliente cliente) {
        framePai = pai;
        frameCode = code;
        this.cliente = cliente;
        initComponents();
        System.out.println("CODIGO "+code);
        switch(code){
            case 0:
                this.jButton2.setText("Criar Room");
            case 1:
                this.jButton2.setText("Entrar");
            default:
                this.jButton2.setText("Criar Room");
        }
    }
    
    public TesteNovoNewRoomBox() {
        initComponents();
    }
    
    
    @Action public void closeNewRoomBox() {
        dispose();
    }
    
    @Action public void createVerify(){
        if(frameCode==0){
            if (framePai.criaSala(this.nomeRoom.getText())){
                //TODO ENTRAR NA SALA
                dispose();
            }else{
                JOptionPane.showMessageDialog(null, "Sala ja existe.", "Criar Nova Room", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int x = framePai.entraSala(this.nomeRoom.getText());
            if (x == 0){
                dispose();
            }else if (x==-1) {
                 JOptionPane.showMessageDialog(null, "Voce ja esta conectado nessa sala.", "Criar Nova Room", JOptionPane.ERROR_MESSAGE);
            }else if (x==-2) {
                 JOptionPane.showMessageDialog(null, "Sala não existe.", "Criar Nova Room", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        nomeRoom = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(testenovo.TesteNovoApp.class).getContext().getResourceMap(TesteNovoNewRoomBox.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(testenovo.TesteNovoApp.class).getContext().getActionMap(TesteNovoNewRoomBox.class, this);
        jButton1.setAction(actionMap.get("closeNewRoomBox")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("createVerify")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        nomeRoom.setText(resourceMap.getString("nomeRoom.text")); // NOI18N
        nomeRoom.setName("nomeRoom"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nomeRoom, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nomeRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField nomeRoom;
    // End of variables declaration//GEN-END:variables
}
